import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const h5NavHeight = 0;
/*#ifdef APP-PLUS*/
h5NavHeight = 44;
/*#endif*/
/*#ifdef H5*/
// const h5NavHeight = 0;
/*#endif*/

const store = new Vuex.Store({
	state: {
		token: uni.getStorageSync('token') || "",
		info: uni.getStorageSync('info') || {
			head_portrait: "",
			nickname: "",
			address: "",
			is_realname: 0,
			show_phone: "",
			phone: "",
			balance: 0.00,
			invitation_code: null
		},
		loadText: {
			loadmore: '点击或上拉加载更多',
			loading: '努力加载中',
			nomore: '没有更多了'
		},
		h5NavHeight: h5NavHeight,
		market_open: false,
		phb_open: 2,
		payment_src: uni.getStorageSync('payment_src') || "",
	},
	mutations: {
		changeLogin(state, payload) {
			state.info.head_portrait = payload.head_portrait;
			state.info.nickname = payload.nickname;
			state.info.address = payload.address;
			state.info.is_realname = payload.is_realname;
			state.info.show_phone = payload.show_phone;
			state.info.phone = payload.phone;
			state.info.balance = payload.balance;
			state.info.invitation_code = payload.invitation_code;
			uni.setStorageSync('info', payload);
		},
		changeToken(state, payload) {
			state.token = payload;
			uni.setStorageSync('token', payload);
		},
		change_payment_src(state, payload) {
			state.payment_src = payload;
			uni.setStorageSync('payment_src', payload);
		},
		outLogin(state, payload) {
			state.token = null;
			state.info = {
				head_portrait: "",
				nickname: "",
				address: "",
				is_realname: 0,
				show_phone: "",
				balance: 0.00
			};
			uni.removeStorageSync("info");
			uni.removeStorageSync("token");
		},
		changeSetup(state, payload) {
			state.market_open = payload.market_open;
			state.phb_open = payload.phb_open;
		},
	}
})

export default store
